<template>
  <div id="echarts5"></div>
</template>

<script>
import * as echarts from 'echarts';

export default {
  props: ['data'],
  data() {
    return {
      myChart: null
    }
  },
  mounted() {
    this.initEcharts()
  },
  methods: {
    initEcharts() {
      const chartDom = document.getElementById('echarts5')
      this.myChart = echarts.init(chartDom)

    },
    setEChartsOptions(sa_data, sa_labels) {
      let option

      option = {
        title: {
          text: `好评率:`,
          // subtext: 'Fake Data',
          left: 'left'
        },
        tooltip: {
          trigger: 'item'
        },
        grid: {
          bottom: '5%'
        },
        xAxis: {
          type: 'category',
          data: sa_labels
        },
        yAxis: {
          type: 'value'
        },

        series: [
          {
            data: sa_data,
            type: 'line',
            smooth: true
          }
        ]
      };

      this.myChart && this.myChart.setOption(option);
    },
  },
  watch: {
    data({sa_data, sa_labels}) {
      this.setEChartsOptions(sa_data, sa_labels)
    }
  }
}
</script>

<style scoped>
#echarts5 {
  width: 100%;
  height: 500px;
}
</style>
